home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / (Extra Support) / non-universal CIncludes / Threads.h
Text File  |  1995-02-17  |  6KB  |  181 lines

  1. /*
  2.     File:        Threads.h
  3.  
  4.     Contains:    External Interface to Thread Manager
  5.  
  6.     Copyright:    © 1991-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #ifndef __THREADS__
  11. #define __THREADS__
  12.  
  13. #include <Memory.h>
  14.  
  15. /* Thread Gestalt Selectors */
  16. enum {
  17. #define gestaltThreadMgrAttr    'thds'            /* Thread Manager attributes */
  18.     
  19.     gestaltThreadMgrPresent        = 0,            /* bit true if Thread Mgr is present */
  20.     gestaltSpecificMatchSupport    = 1,            /* bit true if Thread Mgr supports exact match creation option */
  21.     gestaltThreadsLibraryPresent = 2            /* bit true if ThreadsLibrary (Native version) has been loaded */
  22. };
  23.  
  24. /* Thread states */
  25. typedef unsigned short            ThreadState;
  26. #define kReadyThreadState        ((ThreadState) 0)
  27. #define kStoppedThreadState        ((ThreadState) 1)
  28. #define kRunningThreadState        ((ThreadState) 2)
  29.  
  30. /* Thread environment characteristics */
  31. typedef void*    ThreadTaskRef;
  32.  
  33. /* Thread characteristics */
  34. typedef unsigned long            ThreadStyle;
  35. #define kCooperativeThread        (1<<0)
  36. #define kPreemptiveThread        (1<<1)
  37.  
  38. /* Thread identifiers */
  39. typedef unsigned long            ThreadID;
  40. #define kNoThreadID                ((ThreadID) 0)
  41. #define kCurrentThreadID        ((ThreadID) 1)
  42. #define kApplicationThreadID    ((ThreadID) 2)
  43.  
  44. /* Options when creating a thread */
  45. typedef unsigned long            ThreadOptions;
  46. #define kNewSuspend                (1<<0)
  47. #define kUsePremadeThread        (1<<1)
  48. #define kCreateIfNeeded            (1<<2)
  49. #define kFPUNotNeeded            (1<<3)
  50. #define kExactMatchThread        (1<<4)
  51.  
  52. /* Information supplied to the custom scheduler */
  53. struct SchedulerInfoRec {
  54.     unsigned long    InfoRecSize;
  55.     ThreadID        CurrentThreadID;
  56.     ThreadID        SuggestedThreadID;
  57.     ThreadID        InterruptedCoopThreadID;
  58. };
  59. typedef struct SchedulerInfoRec SchedulerInfoRec;
  60. typedef SchedulerInfoRec *SchedulerInfoRecPtr;
  61.  
  62. /* Prototype for thread's entry (main) routine */
  63. typedef pascal void *            (ThreadEntryProc)(void *threadParam);
  64. typedef ThreadEntryProc            *ThreadEntryProcPtr;
  65.  
  66. /* Prototype for custom thread scheduler routine */
  67. typedef pascal ThreadID            (ThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
  68. typedef ThreadSchedulerProc        *ThreadSchedulerProcPtr;
  69.  
  70. /* Prototype for custom thread switcher routine */
  71. typedef pascal void                (ThreadSwitchProc)(ThreadID threadBeingSwitched, void *switchProcParam);
  72. typedef ThreadSwitchProc        *ThreadSwitchProcPtr;
  73.  
  74. /* Prototype for thread termination notification routine */
  75. typedef pascal void                (ThreadTerminationProc)(ThreadID threadTerminated, void *terminationProcParam);
  76. typedef ThreadTerminationProc    *ThreadTerminationProcPtr;
  77.  
  78. /* Prototype for debugger NewThread notification */
  79. typedef pascal void                    (DebuggerNewThreadProc)(ThreadID threadCreated);
  80. typedef DebuggerNewThreadProc        *DebuggerNewThreadProcPtr;
  81.  
  82. /* Prototype for debugger DisposeThread notification */
  83. typedef pascal void                    (DebuggerDisposeThreadProc)(ThreadID threadDeleted);
  84. typedef DebuggerDisposeThreadProc        *DebuggerDisposeThreadProcPtr;
  85.  
  86. /* Prototype for debugger schedule notification */
  87. typedef pascal ThreadID                (DebuggerThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
  88. typedef DebuggerThreadSchedulerProc    *DebuggerThreadSchedulerProcPtr;
  89.  
  90. /* Errors */
  91. enum {
  92.     threadTooManyReqsErr    = -617,
  93.     threadNotFoundErr        = -618,
  94.     threadProtocolErr        = -619
  95. };
  96.  
  97. #ifdef __cplusplus
  98. extern "C" {
  99. #endif
  100.  
  101. /* Thread Manager routines */
  102. pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  103.     = {0x303C,0x0501,0xABF2};
  104.  
  105. pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  106.     = {0x303C,0x0402,0xABF2};
  107.  
  108. pascal OSErr GetSpecificFreeThreadCount( ThreadStyle threadStyle, Size stackSize, short *freeCount )
  109.     = {0x303C,0x0615,0xABF2};
  110.  
  111. pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  112.     = {0x303C,0x0413,0xABF2};
  113.  
  114. pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  115.     = {0x303C,0x0414,0xABF2};
  116.  
  117. pascal OSErr NewThread(    ThreadStyle threadStyle,
  118.                         ThreadEntryProcPtr threadEntry,
  119.                         void *threadParam,
  120.                         Size stackSize,
  121.                         ThreadOptions options,
  122.                         void **threadResult,
  123.                         ThreadID *threadMade)
  124.     = {0x303C,0x0E03,0xABF2};
  125.  
  126. pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  127.     = {0x303C,0x0504,0xABF2};
  128.  
  129. pascal OSErr YieldToThread(ThreadID suggestedThread)
  130.     = {0x303C,0x0205,0xABF2};
  131.  
  132. pascal OSErr YieldToAnyThread(void)
  133.     = {0x42A7,0x303C,0x0205,0xABF2};
  134.  
  135. pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  136.     = {0x303C,0x0206,0xABF2};
  137.  
  138. pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  139.     = {0x303C,0x0407,0xABF2};
  140.  
  141. pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  142.     = {0x303C,0x0508,0xABF2};
  143.  
  144. pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  145.     = {0x303C,0x0512,0xABF2};
  146.  
  147. pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  148.     = {0x303C,0x0209,0xABF2};
  149.  
  150. pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  151.     = {0x303C,0x070A,0xABF2};
  152.  
  153. pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  154.     = {0x303C,0x0611,0xABF2};
  155.  
  156. pascal OSErr ThreadBeginCritical(void)
  157.     = {0x303C,0x000B,0xABF2};
  158.  
  159. pascal OSErr ThreadEndCritical(void)
  160.     = {0x303C,0x000C,0xABF2};
  161.  
  162. pascal OSErr SetDebuggerNotificationProcs (    DebuggerNewThreadProcPtr notifyNewThread,
  163.                                             DebuggerDisposeThreadProcPtr notifyDisposeThread,
  164.                                             DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  165.     = {0x303C,0x060D,0xABF2};
  166.  
  167. pascal OSErr GetThreadCurrentTaskRef (ThreadTaskRef *threadTRef)
  168.     = {0x303C,0x020E,0xABF2};
  169.  
  170. pascal OSErr GetThreadStateGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  171.     = {0x303C,0x060F,0xABF2};
  172.  
  173. pascal OSErr SetThreadReadyGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToSet)
  174.     = {0x303C,0x0410,0xABF2};
  175.  
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179.  
  180. #endif /* __THREADS__ */
  181.